package sdk.webview.fmc.com.fmcsdk.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.base.BaseActivity;
import sdk.webview.fmc.com.fmcsdk.bean.AgreementBean;
import sdk.webview.fmc.com.fmcsdk.interfaces.AgreementView;
import sdk.webview.fmc.com.fmcsdk.presenter.AgreementPresenter;
import sdk.webview.fmc.com.fmcsdk.util.Constant;
import sdk.webview.fmc.com.fmcsdk.util.PreferencesHelper;
import sdk.webview.fmc.com.fmcsdk.util.TitleBar;
import sdk.webview.fmc.com.fmcsdk.view.LoginFrameStyleColorButton;

public class AgreementActivity extends BaseActivity<AgreementView, AgreementPresenter> implements AgreementView, View.OnClickListener {


    private TextView tv_agreement;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_agreement;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
//       sharedPrefs.edit().putString(Constant.LOOK_AGREEMENT,"LOOK_AGREEMENT").apply();
        TitleBar viewById = (TitleBar) findViewById(R.id.titlebar);
      int flag =   getIntent().getIntExtra("agreement_flag",0);

        LoginFrameStyleColorButton disagree = (LoginFrameStyleColorButton) findViewById(R.id.disagree);
     LinearLayout ll_button = (LinearLayout) findViewById(R.id.ll_button);
     LoginFrameStyleColorButton agree = (LoginFrameStyleColorButton) findViewById(R.id.agree);
        LoginFrameStyleColorButton bt_back = (LoginFrameStyleColorButton) findViewById(R.id.bt_back);

        if (flag==1){
            ll_button.setVisibility(View.VISIBLE);
        }else {
            bt_back.setVisibility(View.VISIBLE);
        }
        disagree.setOnClickListener(this);
        agree.setOnClickListener(this);
        bt_back.setOnClickListener(this);


        tv_agreement = (TextView) findViewById(R.id.tv_agreement);
        AgreementBean agreementBean = PreferencesHelper.getData(AgreementBean.class);
        if (agreementBean!=null){
            if (sharedPrefs.getInt("lang", 0) == 2) {
                viewById.setTitle(agreementBean.getTitle_ch());
            } else if (sharedPrefs.getInt("lang", 0) == 1) {
                viewById.setTitle(agreementBean.getTitle_en());
            } else {
                viewById.setTitle(agreementBean.getTitle());
            }


            tv_agreement.setText(agreementBean.getContent());
        }
    }

    @Override
    protected AgreementPresenter createPresenter() {
        return new AgreementPresenter();
    }

    @Override
    public void agreementContent(String content) {
        tv_agreement.setText(content);
    }

    @Override
    public void onClick(View view) {
        if (view.getId()==R.id.disagree){
            Intent intent=new Intent();
            intent.putExtra("Agreement_result",1);
            setResult(5043, intent);
            finish();
        }else if (view.getId()==R.id.agree){
            Intent intent=new Intent();
            intent.putExtra("Agreement_result",0);
            setResult(5043, intent);
            finish();

        }else if (view.getId()==R.id.bt_back){
            finish();
        }
    }
}
